var t = o(require("../../../../@babel/runtime/regenerator")),
  a = require("../../../../@babel/runtime/helpers/asyncToGenerator"),
  e = o(require("@/config/index")),
  n = o(require("@/config/page")),
  u = require("@/utils/index"),
  r = require("@/utils/jump");
function o(t) {
  return t && t.__esModule ? t : { default: t };
}
Component({
  properties: { mustSeeList: { type: Object, default: [] } },
  data: {
    CDN: e.default.CDN,
    current: 0,
    audio_current_val: 0,
    audio_current: "0",
    audio_duration: 0,
    audio_status: 0,
  },
  created: function () {
    this.backgroundAudioManager ||
      (this.backgroundAudioManager = wx.getBackgroundAudioManager());
  },
  methods: {
    onChange: function (t) {
      var a = t.detail.current;
      this.setData({ current: a });
    },
    onLeft: function () {
      var t = this.data,
        a = t.current,
        e = t.mustSeeList,
        n = a - 1;
      0 === a && (n = e.length - 1), this.setData({ current: n });
    },
    onRight: function () {
      var t = this.data,
        a = t.current,
        e = a + 1;
      a === t.mustSeeList.length - 1 && (e = 0), this.setData({ current: e });
    },
    onThree: function () {
      var t = this.data,
        a = t.mustSeeList,
        e = t.current;
      (0, r.navigateTo)(n.default.PAGE_WEBVIEW, {
        webUrl: a[e].url_3d,
        title: a[e].name,
      });
    },
    onAudio: function () {
      1 !== this.data.audio_status ? this.onPlay() : this.onStop();
    },
    toItem: function () {
      var t = this.data,
        a = t.mustSeeList,
        e = t.current;
      (0, r.navigateTo)(n.default.PAGE_APPRECIATION_COLLECTION_CARD_INDEX, {
        id: a[e].mainstay_id,
      });
    },
    onPlay: function () {
      var t = this.data.mustSeeList[this.data.current];
      (this.backgroundAudioManager.src &&
        this.backgroundAudioManager.src === t.audio.url) ||
        this.audioInit(),
        this.backgroundAudioManager.play();
    },
    onStop: function () {
      this.backgroundAudioManager.pause();
    },
    audioInit: function () {
      var e = this,
        n = this.data.mustSeeList[this.data.current];
      (this.backgroundAudioManager.title = n.name),
        (this.backgroundAudioManager.src = n.audio.url),
        this.backgroundAudioManager.onTimeUpdate(function () {
          console.log("音频播放进度更新中");
          var t = e.backgroundAudioManager.currentTime,
            a = e.backgroundAudioManager.duration - t;
          e.setData({ audio_current_val: a, audio_current: (0, u.format)(a) });
        }),
        this.backgroundAudioManager.onPlay(function () {
          console.log("开始播放"), e.setData({ audio_status: 1 });
        }),
        this.backgroundAudioManager.onPause(
          a(
            t.default.mark(function a() {
              return t.default.wrap(function (t) {
                for (;;)
                  switch ((t.prev = t.next)) {
                    case 0:
                      console.log("暂停播放"), e.setData({ audio_status: 2 });
                    case 2:
                    case "end":
                      return t.stop();
                  }
              }, a);
            }),
          ),
        ),
        this.backgroundAudioManager.onEnded(
          a(
            t.default.mark(function a() {
              return t.default.wrap(function (t) {
                for (;;)
                  switch ((t.prev = t.next)) {
                    case 0:
                      console.log("停止播放"), e.setData({ audio_status: 0 });
                    case 2:
                    case "end":
                      return t.stop();
                  }
              }, a);
            }),
          ),
        ),
        this.backgroundAudioManager.onStop(function () {
          console.log("音频播放结束"),
            e.setData({
              audio_status: 0,
              audio_current_val: 0,
              audio_current: (0, u.format)(0),
            });
        }),
        this.backgroundAudioManager.onSeeked(function () {});
    },
  },
});
